Authentication
The BindAI REST API v0.1 uses a simple environment-based API-key authentication mechanism for protected endpoints. The authentication model is:BINDAI_API_KEY environment variable.
Authentication is intentionally lightweight for the initial v0.1 public API. There is no database-backed identity system, user-management system, or built-in multi-tenant authorization layer.
API Key Configuration
Set the API key in the environment where the BindAI API process is running:Authorization Header
Clients authenticate using the HTTPAuthorization header with the Bearer scheme:
Bearer must match the configured BINDAI_API_KEY.
The current implementation compares the complete authorization value against:
Protected Endpoints
The v0.1 API protects the following resource groups with API-key authentication:Public Health Endpoint
The health endpoint does not require authentication:/health public allows deployment infrastructure and container health checks to verify basic API availability without storing API credentials.
The health endpoint reports API application availability. It does not perform a complete health check of every configured model provider, connection, or external dependency.
Authentication Flow
For a normally configured deployment, the request flow is:Authorization header is missing, or its value does not exactly match the configured Bearer token, the authentication dependency raises 401 Unauthorized.
Missing Authentication
A protected endpoint called without an authorization header is rejected when API-key authentication is configured. For example:Invalid Authentication
A request with an incorrect API key is also rejected. For example:Correct Authentication
A request containing the configured API key is allowed to reach the protected resource. For example:Missing API Key Configuration
The API expectsBINDAI_API_KEY to be configured before protected routes are served.
If the environment variable is not configured, the current authentication dependency raises a configuration RuntimeError rather than returning a normal 401 Unauthorized response.
Conceptually:
BINDAI_API_KEY itself is missing:
BINDAI_API_KEY before exposing protected API routes.
For example:
PowerShell
When using Windows PowerShell, the API key can be stored in an environment variable:Docker
When running the API with Docker, provide the key through the container environment:Docker Compose
When using Docker Compose, the API key can be supplied through the environment configuration. For example:docker-compose.yml.
For production deployments, use the secret-management facilities provided by the hosting environment when available.
Environment Configuration
A local BindAI deployment may contain several different credentials:Secret Management
API keys should be treated as secrets. Do not store production API keys in:- Source code
- Git repositories
- Dockerfiles
- Public documentation
- Public configuration files
- Client-side JavaScript
- URLs
- Query parameters
- Error messages
- Ordinary application logs
Key Generation
The BindAI v0.1 API does not provide a built-in API-key generation service. The configured key is supplied by the deployment environment. A deployment can generate a strong random secret using an appropriate operating-system or secret-management facility. For example, Python can generate a random token:Key Rotation
The v0.1 authentication model uses one configured API key. Changing the value ofBINDAI_API_KEY changes the key accepted by the API after the application environment is refreshed and the API process is restarted or redeployed.
A simple rotation process is:
Client Security
Clients should protect their BindAI API keys in the same way they protect other service credentials. Avoid putting a BindAI API key into:- Browser source code
- Public mobile applications
- Public GitHub repositories
- Frontend configuration shipped to users
- URLs
- Query parameters
HTTPS
API-key authentication should be used over HTTPS when the API is exposed outside a trusted local network. A production deployment should normally look like:http://localhost:8000 is appropriate for testing.
Reverse Proxy Deployment
A production deployment may place a reverse proxy in front of the BindAI API:- TLS termination
- Network restrictions
- Rate limiting
- Request-size limits
- Access logging
- IP filtering
Rate Limiting
The v0.1 BindAI API authentication layer does not provide built-in rate limiting. When exposing the API publicly, rate limiting should be provided by the surrounding infrastructure when required. For example:- Accidental request loops
- Excessive API usage
- Denial-of-service attempts
- Unexpected client behavior
Authentication and Agent Access
Authentication protects access to the REST API. It does not determine what an individual agent is allowed to do. For example:Authentication and Connections
Connections may require their own credentials. For example:Authentication and Model Providers
Model-provider credentials are also separate from the BindAI API key. For example:Authentication and Background Runs
Background-run endpoints require the same API authentication as other protected resources. For example:Authentication Errors
Authentication failures should be treated differently from application execution failures. Authentication failure:Operational Logging
Authentication-related operational information can be useful for debugging and security monitoring. However, never log the API key itself. Safe information may include:- Request timestamp
- Endpoint
- HTTP method
- Response status
- Request duration
- Application-level request identifier
Development vs Production
Local development can use a simple environment variable:Current v0.1 Authentication Model
The current authentication architecture is intentionally small:- Database-backed identity
- User accounts
- Role management
- Multiple managed API keys
- OAuth
- OpenID Connect
- Built-in multi-tenant authorization
- Persistent API-key storage
- API-key expiration or revocation
Future Authentication
Future BindAI releases may introduce more advanced authentication and authorization capabilities. Potential areas include:- Multiple API keys
- Persistent API-key management
- Key expiration
- Key revocation
- User accounts
- OAuth
- OpenID Connect
- Role-based access control
- Per-project permissions
- Per-agent permissions
- Per-tool permissions
- Multi-tenant authorization
- Audit logging
Security Checklist
Before exposing a BindAI API deployment publicly:- Generate a strong API key.
- Store the key securely.
- Configure
BINDAI_API_KEY. - Do not commit the key to source control.
- Use HTTPS.
- Do not put the API key in URLs.
- Do not expose the key in browser code.
- Do not log the key.
- Use least-privilege credentials for external connections.
- Protect provider credentials.
- Consider rate limiting.
- Monitor authentication failures.
- Rotate credentials when appropriate.
- Restrict network access where possible.
Testing Authentication
The API package includes authentication tests. Run the API test suite with:- Valid API key
- Invalid API key
- Missing API key
- Public health endpoint
BINDAI_API_KEY is configured, the first request should be rejected with 401 Unauthorized.
The second request should be processed when the key matches BINDAI_API_KEY.
